
class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        unordered_set<int> hash;
        for (auto& i : nums) {
            hash.insert(i);
        }

        int maxSerQ = 0;
        for (auto& num : hash) {
            if (!hash.count(num - 1)) {
                int curNum = num;
                int curSerQ = 1;

                while (hash.count(curNum + 1)) {
                    curNum += 1;
                    curSerQ++;
                }
                maxSerQ = max(maxSerQ, curSerQ);
            }
        }
        return maxSerQ;
    }
};
